home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / gloss.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.6 KB  |  74 lines

  1. /*
  2.  * gloss.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * gloss.c,v 4.1 1994/08/09 08:02:40 explorer Exp
  17.  *
  18.  * gloss.c,v
  19.  * Revision 4.1  1994/08/09  08:02:40  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:14  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:42:30  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "gloss.h"
  31.  
  32. Gloss *
  33. GlossCreate(glossiness)
  34. Float glossiness;
  35. {
  36.     Gloss *gloss;
  37.  
  38.     gloss = (Gloss *)Malloc(sizeof(Gloss));
  39.     gloss->glossy = 1. - glossiness;
  40.     return gloss;
  41. }
  42.  
  43. void
  44. GlossApply(gloss, prim, ray, pos, norm, gnorm, surf)
  45. Gloss *gloss;
  46. Geom *prim;
  47. Ray *ray;
  48. Vector *pos, *norm, *gnorm;
  49. Surface *surf;
  50. {
  51.     Vector uaxis, vaxis, point, norminc;
  52.     extern void UnitCirclePoint();
  53.  
  54.     /*
  55.      * Find coordinate system with norm as the Z axis.
  56.      */
  57.     VecCoordSys(norm, &uaxis, &vaxis);
  58.     /*
  59.      * Find point on unit circle based on sample #.
  60.      */
  61.     UnitCirclePoint(&point, ray->sample);
  62.     /*
  63.      * Perturb normal appropriately.
  64.      */
  65.     VecComb(gloss->glossy * point.x, uaxis,
  66.         gloss->glossy * point.y, vaxis,
  67.         &norminc);
  68.     VecAdd(*norm, norminc, norm);
  69.     /*
  70.      * Renormalize.
  71.      */
  72.     (void)VecNormalize(norm);
  73. }
  74.